/**
 * Copyright (C) 2021-2022 maminjie <canpool@163.com>
 * SPDX-License-Identifier: LGPL-2.1
 * Powered by Qt-Advanced-Docking-System
**/

#pragma once

#include "qads_global.h"

#include <QWidget>

QADS_BEGIN_NAMESPACE

class DockWidget;
class DockPannel;
class DockTabPrivate;

class QADS_EXPORT DockTab : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(bool activeTab READ isActive WRITE setActive NOTIFY activeChanged)
    Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)

public:
    DockTab(DockWidget *DockWidget, QWidget *parent = nullptr);
    ~DockTab() override;

    DockWidget *dockWidget() const;

    bool isActive() const;
    void setActive(bool active);

    const QIcon &icon() const;
    void setIcon(const QIcon &icon);

    QSize iconSize() const;
    void setIconSize(const QSize &size);

    QString text() const;
    void setText(const QString &title);

    void setElideMode(Qt::TextElideMode mode);
    bool isTitleElided() const;

    bool isClosable() const;

    void setVisible(bool visible) override;

    void updateStyle();

signals:
    void activeChanged();
    void clicked();
    void closeRequested();
    void closeOtherRequested();
    void moved(const QPoint &globalPos);
    void elidedChanged(bool elided);

protected:
    void setDockPannel(DockPannel *pannel);

protected:
    bool event(QEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;
    void contextMenuEvent(QContextMenuEvent *event) override;

private:
    void onDockWidgetFeaturesChanged();
    void detachDockWidget();

private:
    DockTabPrivate *d;
    friend class DockTabPrivate;
    friend class DockWidget;
}; // class DockTab

QADS_END_NAMESPACE
